/*
 *  Copyright 2008-2010 the original author or authors.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.openaecfm.spf.model;

/**
 * The header entity.
 * @author Qiu Kuining
 */
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class HeaderEntity implements Node {

    /**
     * The NodeType of HeaderEntity.
     * @return
     */
    @Override
    public final NodeType getNodeType() {
        return NodeType.HEADER_ENTITY;
    }
    private String keyword;
    private List<Parameter> parameters = new ArrayList<Parameter>();

    public HeaderEntity() {
    }

    public HeaderEntity(String keyword) {
        this.keyword = keyword;
    }

    /**
     * Add a parameter.
     * @param p
     */
    public void addParameter(Parameter p) {
        parameters.add(p);
    }

    /**
     * Get the parameters.
     * @return
     */
    public List<Parameter> getParameters() {
        return parameters;
    }

    /**
     * Get the parameter by index i.
     * @param i
     * @return
     */
    public Parameter getParameter(int i) {
        return parameters.get(i);
    }

    /**
     * To string.
     * @return
     */
    @Override
    public String toString() {
        java.lang.StringBuffer b = new java.lang.StringBuffer();
        b.append(keyword).append("(");
        Iterator<Parameter> i = parameters.iterator();

        if (i.hasNext()) {
            b.append(i.next());
        }
        while (i.hasNext()) {
            b.append(",").append(i.next());
        }
        b.append(");\n");
        return b.toString();
    }

    /**
     * Get the keyword of HeaderEntity.
     * @return
     */
    public String getKeyword() {
        return keyword;
    }

    /**
     * Set the keyword of HeaderEntity.
     * @param keyword
     */
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    /**
     * Add a child node.
     * @param n
     */
    @Override
    public void addChild(Node n) {
        if (n instanceof Parameter) {
            parameters.add((Parameter) n);
        }
    }
}
